package com.jhgk.jhcee.forecast.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jhgk.jhcee.bfk.mapper.FsdMapper;
import com.jhgk.jhcee.bfk.model.Fsd;
import com.jhgk.jhcee.bfk.model.FsdExample;
import com.jhgk.jhcee.common.enums.BasisResultEnum;
import com.jhgk.jhcee.common.resultful.BasisResultful;
import com.jhgk.jhcee.common.resultful.PageResultful;
import com.jhgk.jhcee.forecast.domain.model.FsdModel;
import com.jhgk.jhcee.forecast.service.FsdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/11 14:18.
 */
@Service(value = "FsdServiceImpl")
public class FsdServiceImpl implements FsdService {

    @Autowired
    FsdMapper fsdMapper;

    @Override
    public BasisResultful<Object> addBatchData(List<Fsd> fsds) {
        if (fsds.isEmpty()) {
            return BasisResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }

        return null;
    }

    @Override
    public BasisResultful<Object> updateBatchData(List<Fsd> fsds) {
        if (fsds.isEmpty()) {
            return BasisResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }

        return null;
    }

    @Override
    public PageResultful<PageInfo<Fsd>> searchAllPage(FsdModel fsdModel) {
        if (null == fsdModel) {
            return PageResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }
        FsdExample example = new FsdExample();
        FsdExample.Criteria criteria = example.createCriteria();
        criteria.andNfEqualTo(fsdModel.getNf());
        criteria.andSydEqualTo(fsdModel.getSyd());
        PageHelper.startPage(fsdModel.getPage(),fsdModel.getLimit());
        List<Fsd> fsds = fsdMapper.selectByExample(example);
        if (fsds.isEmpty()) {
            return PageResultful.fail(BasisResultEnum.QUERY_IS_NULL);
        }
        PageInfo<Fsd> pageInfo = new PageInfo<>(fsds);
        return PageResultful.success(pageInfo);
    }

    @Override
    public BasisResultful<Object> searchAll(Fsd fsd) {
        if (null == fsd) {
            return BasisResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }
        FsdExample example = new FsdExample();
        FsdExample.Criteria criteria = example.createCriteria();
        criteria.andNfEqualTo(fsd.getNf());
        criteria.andSydEqualTo(fsd.getSyd());
        List<Fsd> fsds = fsdMapper.selectByExample(example);
        if (fsds.isEmpty()) {
            return BasisResultful.fail(BasisResultEnum.QUERY_IS_NULL);
        }
        return BasisResultful.success(fsds);
    }
}
